<?PHP

function connectSAP(){

    //SAP connection
        $LOGIN = array ("ASHOST"=>"153.109.124.33",
                        "SYSNR"=>"D07",
                        "CLIENT"=>"100",
                        "USER"=>"M646-04",
                        "PASSWD"=>"hevs12",
                        "CODEPAGE"=>"1100");

        //Try to connect to SAP using our Login array
        $rfc = saprfc_open ($LOGIN);
        if(!$rfc){
            echo "The RFC connection has failed with the following error:".saprfc_error();
            exit;
        }
        
        return  $rfc;
}
function connectLDAP($username, $password){
    $server = "153.109.141.54";
    $port = "10389";
    // Connection to LDAP server
    $ldapconn = ldap_connect($server,$port)
                    or die('Impossible de se connecter au serveur LDAP');
    
    if ($ldapconn) {
        ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
        // Connection to LDAP server$ldaprdn  = "cn=".$username.", ou=users, ou=system";    // DN ou RDN LDAP
        $ldaprdn  = "cn=".$username.", ou=users, ou=system";    // DN ou RDN LDAP
        $ldappass = "{MD5}".base64_encode(pack("H*",md5( $password)));
        $ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappass)
                or die($texts['unknown_login'][$_SESSION['lang']]);

        $filter="cn=$username";
        $justthese = array("ou", "sn", "givenname", "mail", "uid",
                            "facsimileTelephoneNumber", "telephoneNumber", 
                            "mobile","postalAddress","l","postalCode", "o",
                            "codestateOrProvinceName");

        $sr=ldap_search($ldapconn, $ldaprdn, $filter, $justthese);

        $info = ldap_get_entries($ldapconn, $sr);  
        
    }
    else
        $info = 'Erreur';
    return $info;
}